package com.lx.vcode;

import com.lx.vcode.bean.VcodePropertise;
import com.lx.vcode.web.VcodeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@AutoConfiguration
@ComponentScan("com.lx.vcode")
//  matchIfMissing = true        没有enable 默认打开
@ConditionalOnProperty(prefix = "vcode", name = "enable", matchIfMissing = true)
@EnableConfigurationProperties(VcodePropertise.class)
public class VcodeConfigration implements WebMvcConfigurer {


    @Autowired
    VcodePropertise vcodePropertise;

    @Autowired
    VcodeInterceptor vcodeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*registry.addInterceptor(vcodeInterceptor)
                .addPathPatterns(vcodePropertise.getScope());*/

        if (!vcodePropertise.getScope().isEmpty() && vcodePropertise.getScope() != null) {
            registry.addInterceptor(vcodeInterceptor)
                    .addPathPatterns(vcodePropertise.getScope());
        }
    }

    public VcodeConfigration() {
        System.out.println("---------------------------------");
    }
}
